package com.roc.web.action.windcontroll;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.roc.page.BaseSearchCondition;
import com.roc.page.PaginationBaseAction;
import com.roc.pojo.Operators;
import com.roc.pojo.TblMgmInsCashHeadRoute;
import com.roc.service.CashHeadRouteService;
import com.roc.util.Constance;
import com.roc.util.constant.Constant;
import com.roc.util.constant.Role;

@Component
@Scope("prototype")
@Namespace("/windControllSta")
public class CashHeadRouteAction extends PaginationBaseAction{
	
	private Logger logger=LogManager.getLogger(CashHeadRouteAction.class);
	
	@Autowired
	private CashHeadRouteService cashHeadRouteService;
	
	private TblMgmInsCashHeadRoute tblMgmInsCashHeadRoute;
	
	private TblMgmInsCashHeadRoute someRoute;
	
	@Action(value="headRouteJsp",results={ @Result(name="success",location="/pages/windControllSta/headRouteJsp.jsp")})
	public String headRouteJsp(){
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		if(op.getRoleType().equals(Role.AGENT.getCode())&&!"sdsyb".equals(op.getAccountNo())) {
			addActionError("当前登录账号无权限访问!!!");
			return ERROR;
		}
		
		return SUCCESS;
		}
	
	@Action(value="queryHeadRoute",results={ @Result(name="success",location="/pages/windControllSta/headRouteJsp.jsp")})
	public String queryHeadRoute(){
		Operators op = (Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		if(op.getRoleType().equals(Role.AGENT.getCode())&&!"sdsyb".equals(op.getAccountNo())) {
			addActionError("当前登录账号无权限访问!!!");
			return ERROR;
		}
		List<TblMgmInsCashHeadRoute> routeList = new ArrayList<TblMgmInsCashHeadRoute>();
		try {
			routeList = cashHeadRouteService.queryHeadRouteList(tblMgmInsCashHeadRoute);
			getRequest().setAttribute("routeList", routeList);
		} catch (Exception e) {
			logger.info("查询寸头信息异常："+e);
		}
		
		return SUCCESS;
		
	}
	
	@Action(value="findHeadRouteDetail",results={ @Result(name="success",location="/pages/windControllSta/modifySomeRoute.jsp")})
	public String findHeadRouteDetail(){
		List<TblMgmInsCashHeadRoute> routeList = new ArrayList<TblMgmInsCashHeadRoute>();
		try {
			String insCdPre = Constance.Null2EmptyTrim(tblMgmInsCashHeadRoute.getInsCdPre());
			String procCd = Constance.Null2EmptyTrim(tblMgmInsCashHeadRoute.getProcCd());
			String routeInsCd = Constance.Null2EmptyTrim(tblMgmInsCashHeadRoute.getRouteInsCd());
			if(!"".equals(insCdPre) && !"".equals(procCd) && !"".equals(routeInsCd)){
				routeList = cashHeadRouteService.queryHeadRouteList(tblMgmInsCashHeadRoute);
				someRoute = routeList.get(0);
			}else{
				someRoute = new TblMgmInsCashHeadRoute();
			}
			
		} catch (Exception e) {
			logger.info("查询某代付通道寸头信息异常");
		}
		return SUCCESS;
	}
	
	@Action(value="modifyHeadRoute",results={ @Result(name="success",location="/pages/windControllSta/modifySomeRoute.jsp")})
	public String modifyHeadRoute(){
		try {
			cashHeadRouteService.modifySomeHeadRoute(someRoute);
			getRequest().setAttribute("msg", true);
		} catch (Exception e) {
			logger.info("修改寸头信息异常："+e);
			getRequest().setAttribute("msg", false);
		}
		return SUCCESS;
	}
	

	@Override
	protected BaseSearchCondition getSearchConditionFromSubClass()
			throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void setSearchConditionToSubClass(
			BaseSearchCondition searchCondition) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected void setSearchToConditionSession(
			BaseSearchCondition searchCondition) {
		// TODO Auto-generated method stub
		
	}

	@Override
	protected BaseSearchCondition getSearchConditionFromSession() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected String getInitPageSize() {
		// TODO Auto-generated method stub
		return null;
	}

	public TblMgmInsCashHeadRoute getTblMgmInsCashHeadRoute() {
		return tblMgmInsCashHeadRoute;
	}

	public void setTblMgmInsCashHeadRoute(
			TblMgmInsCashHeadRoute tblMgmInsCashHeadRoute) {
		this.tblMgmInsCashHeadRoute = tblMgmInsCashHeadRoute;
	}

	public TblMgmInsCashHeadRoute getSomeRoute() {
		return someRoute;
	}

	public void setSomeRoute(TblMgmInsCashHeadRoute someRoute) {
		this.someRoute = someRoute;
	}
	
	
	
	
}
